package cn.circle.mobile.controller;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

import cn.circle.system.model.CommodityCategory;
import cn.circle.system.model.CommodityInfo;
/*import cn.circle.mobile.utils.WeChatProperties;*/
import cn.circle.system.pagemodel.ReturnInfo;

/**
 * 
 * @author 
 * 操作商品
 */
@Controller
@EnableWebMvc
@SuppressWarnings("unchecked")
public class MobileCommodityController extends FrontBaseController {
	
	private static final Log log = LogFactory.getLog(MobileCommodityController.class);
	/**
	 * 进入商品页面
	 */
	@RequestMapping(value="/mobile/store")
	public String index(HttpServletRequest request, Map<String, Object> map, HttpServletResponse response){
		
			return super.index("/WEB-INF/pages/mobile/main/food/commodity_main.jsp", request);
		
	}
	/**
	 * 
	 */
	@ResponseBody
	@RequestMapping(value = "/mobile/getComInfo")
	public ReturnInfo getCommodity(ReturnInfo info, Integer page, Integer rows) {
		
		if (page != null && rows != null) {
		List<CommodityInfo> lstAll = null;

		try {
			String hql = " from  CommodityInfo o where o.status = 9 and o.number > 0 order by createTime desc  ";
			lstAll = super.find(hql, page, rows);
			info.setRows(super.count("select count(*) " + hql)); // 总记录数
			info.setObj(lstAll);
		} catch (Exception e) {
			log.info("异常" + e.getMessage());
			}
		}
		return info;
	}
	
	@ResponseBody
	@RequestMapping(value = "/mobile/getCommodityCategory")
	public ReturnInfo getCommodityCategory(ReturnInfo info, Integer page, Integer rows) {
		
		if (page != null && rows != null) {
		List<CommodityCategory> lstAll = null;

		try {
			String hql = " from  CommodityCategory o where o.status = 9";
			lstAll = super.find(hql, page, rows);
			info.setRows(super.count("select count(*) " + hql)); // 总记录数
			info.setObj(lstAll);
		} catch (Exception e) {
			log.info("异常" + e.getMessage());
			}
		}
		return info;
	}
}


